/*
 * WinnerDialog.java
 */

package othello.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class WinnerDialog extends JDialog implements ActionListener{
    
    private JButton okButton = new JButton("OK");
    private ImageIcon image = new ImageIcon(getClass().getClassLoader().getResource("img/winner.jpg"));
    private JLabel label = new JLabel(image);
    private JPanel panel = new JPanel();
    private JPanel jpnlButton = new JPanel();
    private FlowLayout flw = new FlowLayout();
    
    public WinnerDialog(Frame owner, String name) {
        
        super(owner);
        
        this.setTitle("Congratulations, you won!");
        
        panel.setLayout(flw);
        panel.add(new JLabel(name + " wins!"));
        panel.setBackground(Color.WHITE);
        
        this.getContentPane().add(panel,BorderLayout.CENTER);
        
        jpnlButton.add(okButton);
        jpnlButton.setBackground(Color.WHITE);
        okButton.addActionListener(this);
        
        this.getContentPane().add(jpnlButton, BorderLayout.SOUTH);
        this.getContentPane().add(label,BorderLayout.NORTH);
        
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.setSize(250,420);
        this.setLocationRelativeTo(owner);
        this.getContentPane().setBackground(Color.WHITE);
        setVisible(true);
    }
    
    //Closes the frame when OK is clicked on.
    public void actionPerformed(ActionEvent e) {
        dispose();
    }
}
